home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / Testing & Debugging / BusErrorTest / BusErrTestInit.a < prev    next >
Encoding:
Text File  |  1993-01-18  |  3.3 KB  |  125 lines  |  [TEXT/MPS ]

  1. ***********************************************************************
  2. ***
  3. ***        BusErrTest
  4. ***        
  5. ***        Build commands:
  6. ***
  7. ***        asm BusErrTest.a
  8. ***        link BusErrTest.a.o -o BusErrTest
  9. ***
  10. ***********************************************************************
  11.  
  12.                     STRING    ASIS
  13.                     PRINT    OFF
  14.                     INCLUDE 'Traps.a'
  15.                     INCLUDE 'QuickEqu.a'
  16.                     INCLUDE 'SysEqu.a'
  17.                     PRINT    ON
  18.                     machine mc68030
  19.  
  20. ***********************************************************************
  21.  
  22. UnImpTrap        EQU        $A89F
  23. HWPriv            EQU        $A198
  24.  
  25. ***********************************************************************
  26. InitEntry        PROC;MAIN
  27.         IMPORT    OldGuy
  28.         IMPORT    BusErrProc
  29.         IMPORT    theEnd
  30.         IMPORT    InstallVector
  31.         IMPORT    ReplaceVector
  32.         
  33.         lea            theEnd,a0
  34.         lea            BusErrProc,a1
  35.         suba.l        a1,a0
  36.         move.l        a0,d0
  37.         move.l        d0,d2
  38.         _NewPtr        ,SYS,CLEAR
  39.         move.l        a0,d1
  40.         beq.s        abort
  41.         lea            BusErrProc,a0
  42.         move.l        d1,a1
  43.         move.l        d2,d0
  44.         _blockMove
  45.         bsr            InstallVector
  46. abort    rts
  47.         ENDP
  48. ***********************************************************************
  49. InstallVector    PROC    EXPORT
  50.  
  51.         IMPORT    OldGuy
  52.         IMPORT    BusErrProc
  53.         
  54.         move.l        d1,a0                ;OldGuy is a place to keep the original bus error vector
  55.         move.l        8,OldGuy-BusErrProc(a0)    ;so fill it up with the vector, victor
  56.         move.l        a0,8                ;and install it
  57. outtahere
  58.         rts
  59.         ENDP
  60.         
  61. ***********************************************************************
  62. CauseBusErr        PROC    EXPORT        
  63.         
  64.         movem.l        a0/d0,-(sp)            ;preserve the register we use
  65.         move.l        #$FFFFFFFF,a0        ;this address looks pretty dangerous...
  66.         move.b        (a0),d0
  67.         movem.l        (sp)+,a0/d0            ;restore the registers we use
  68.         rts                                ;it's Miller time
  69.         ENDP
  70.         
  71. ***********************************************************************
  72. ReplaceVector    PROC    EXPORT
  73.         IMPORT    OldGuy
  74.         IMPORT    BusErrProc
  75.  
  76.         movem.l        a0-a1,-(sp)            ;preserve reg
  77.         lea            8,a0                ;point to the 680x0 bus error vector
  78.         move.l        8,a1
  79.         move.l        OldGuy-BusErrProc(a1),(a0)            ;and fill it full of the original
  80.         move.l        a1,a0
  81.         _disposPtr
  82.         movem.l        (sp)+,a0-a1            ;restore reg
  83.         rts                                ;system handler vector
  84.         ENDP
  85.         
  86. ***********************************************************************
  87. BusErrProc        PROC    EXPORT            ;THIS CODE ASSUMES THE BUS ERROR
  88.                                         ;EXCEPTION STACK FRAME FOR THE 
  89.                                         ;68030!!! (REF MOTOROLA 68030 USER'S
  90.                                         ;MANUAL PAGE 8-25)
  91.         IMPORT    OldGuy
  92. RegOffset    EQU        4*2
  93.  
  94.         movem.l        a1/d0,-(sp)            ;take only pictures, leave only footprints
  95.         move.b        6+RegOffset(sp),d0    ;get the id nibble for the stack frame
  96.  
  97.         andi.b        #$F0,d0                ;don't care 'bout the lower nibble...
  98.         cmpi.b        #$B0,d0                ;make sure it's the one we like
  99.         bne.s        NotOurs                ;if not, pass it on to system handler
  100.         bclr.b        #0,$A+RegOffset(sp)    ;clear DF bit of Special Status Reg
  101.                                         ;so that the instruction will not be re-tried
  102.         move.l        scrnbase,a1            ;let the user know we arrived by inverting
  103.         move.w        #$2ff,d0            ;a hunk o' screen
  104.         
  105. Loop
  106.         eori.l        #$ffffffff,(a1)+    ;we do a long word at a time
  107.         dbra        d0,Loop                ;till d0 goes negative
  108.         
  109.         movem.l        (sp)+,a1/d0            ;clean up after ourselves
  110. ret        rte                                ;and return from the exception
  111. NotOurs
  112.         movem.l        (sp)+,a1/d0            ;restore battered registers
  113.         move.l        OldGuy,-(sp)        ;and pass control onto the system
  114.         rts                                ;bus error handler
  115.         ENDP
  116.         
  117. ***********************************************************************
  118. OldGuy    PROC    EXPORT
  119.         DC.L    0                        ;a long word for storage
  120.         ENDP
  121.         
  122. theEnd    PROC    EXPORT
  123.         ENDP
  124.  
  125.         END